package com.evil.common.core.exception;

import com.evil.common.core.enums.RCodeEnum;
import lombok.Getter;

/**
 * @author liyang
 */
public class BusinessException extends RuntimeException {

    @Getter
    protected Integer code;

    @Getter
    protected String message;

    @Getter
    protected Object data;

    public BusinessException() {
        this.code = RCodeEnum.ERROR.getCode();
        this.message = "业务异常";
        this.data = null;
    }

    public BusinessException(RCodeEnum rCodeEnum) {
        this.code = rCodeEnum.getCode();
        this.message = rCodeEnum.getMessage();
        this.data = null;
    }

    public BusinessException(RCodeEnum rCodeEnum, String message) {
        this.code = rCodeEnum.getCode();
        this.message = message;
        this.data = null;
    }

    public BusinessException(Integer code, String message) {
        this.code = code;
        this.message = message;
        this.data = null;
    }

    public BusinessException(RCodeEnum rCodeEnum, Object data) {
        this.code = rCodeEnum.getCode();
        this.message = rCodeEnum.getMessage();
        this.data = data;
    }

    public BusinessException(RCodeEnum rCodeEnum, String message, Object data) {
        this.code = rCodeEnum.getCode();
        this.message = message;
        this.data = data;
    }

    public BusinessException(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public BusinessException formatMessage(Object... msg) {
        this.message = String.format(this.message, msg);
        return this;
    }
}
